<?php
/**
 * Created by PhpStorm.
 * User: xieky
 * Date: 2017/8/7
 * Time: 17:34
 */

namespace mybackend\controllers;
use common\services\myhtsq\ParamsService;

class ParamsController extends BaseController
{
    /*
     * 获取数据
     */
    public function actionGetParamsCarryoverTime(){
        $data = ParamsService::getParamsCarryoverTime();
        return $this->exportJson($data,0,'');
    }

    public function actionSaveParamsCarryoverTime(){
        $data = $this->getParam('carryovertime','post');
        if(empty($data)){
            $this->errorParam();
        }
        $result = ParamsService::saveParamsCarryoverTime($data);
        if($result){
            return $this->exportJson($result,0,'');
        }else{
            return $this->exportJson($result,999,'保存信息失败!');
        }
    }

    public function actionGetCanChangeCarryoverTime(){
        if(ParamsService::getCanChangeCarryoverTime()){
            return $this->exportJson([],0,'');
        }else{
            return $this->exportJson([],999,'不能修改结转周期!');
        }
    }

    /**
     * @return type
     */
    public function actionGetBalanceRateInfo(){
        $data = ParamsService::getBalanceRateInfo();
        return $this->exportJson($data,'0','');
    }

    /**
     * @return type
     */
    public function actionGetBalanceRate(){
        $keyword = $this->getParam('keyword','post');
        $data = ParamsService::getBalanceRate($keyword);
        return $this->exportJson($data,'0','');
    }

    public function actionSaveParamsBalanceRate(){
        $params = $this->getParam('balancerate','post');
        if(empty($params)){
            $this->errorParam();
        }
        $cansave = ParamsService::checkCanSave($params);
        if(!$cansave){
            return $this->exportJson([],999,'该产品及区域对应记录已设置!!');
        }

        $result = ParamsService::saveBalanceRate($params);
        if($result){
            return $this->exportJson($result,0,'');
        }else{
            return $this->exportJson($result,999,'保存信息失败!');
        }
    }
}